#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

typedef struct SNode* PtrToSNode;
struct SNode {
    int data;
    PtrToSNode next;
};
typedef PtrToSNode Stack;

Stack CreateStack () {
    Stack S = (Stack)malloc(sizeof(struct SNode));
    S->next = NULL;
    return S;
};

bool StackEmpty ( Stack S ) {
    return ( S->next == NULL );
}

void Push ( Stack S, int X ) {
    Stack tmp = CreateStack();
    tmp->data = X;
    tmp->next = S->next;
    S->next = tmp;
}

int Pop ( Stack S ) {
    if ( StackEmpty(S) ) {
        printf("Stack Empty\n");
        // return;
        exit(-1);
    }
    Stack tmp = S->next;
    int X = tmp->data;
    S->next = tmp->next;
    free(tmp);
    return X;
}

void traversal ( int* pre, int* in, int* post, int preL, int inL, int postL, int n ) {
    if ( n == 0 ) return;
    else if ( n == 1 ) {
        post[postL] = pre[preL];
        return;
    }
    int root = pre[preL];
    post[postL+n-1] = root;
    int cnt = 0, L = 0, R = 0;
    for ( cnt = 0; cnt < n; cnt++ ) if ( in[inL+cnt] == root ) break;
    L = cnt; R = n-L-1;
    traversal(pre,in,post,preL+1,inL,postL,L);
    traversal(pre,in,post,preL+L+1,inL+L+1,postL+L,R);
}

int main () {
    char input[5];
    int N, i, num_to_push, p_to_pre = 0, p_to_in = 0;
    int* pre, *in, *post;
    Stack S = CreateStack();
    scanf("%d", &N);
    pre = (int*)malloc(sizeof(int)*N);
    memset(pre,0,N);
    in = (int*)malloc(sizeof(int)*N);
    memset(in,0,N);
    post = (int*)malloc(sizeof(int)*N);
    memset(post,0,N);
    for ( i = 0; i < N*2; i++ ) {
        scanf("%s",input);
        if ( strlen(input) == 4 ) {
            scanf("%d", &num_to_push);
            Push(S,num_to_push);
            pre[p_to_pre] = num_to_push;
            p_to_pre++;
        } else {
            in[p_to_in] = Pop(S);
            p_to_in++;
        }
    }
    traversal(pre,in,post,0,0,0,N);
    printf("%d", post[0]);
    for ( i = 1; i < N; i++ ) printf(" %d", post[i]);
    printf("\n");
    return 0;
}